$(function(){
    moon.info("欢迎来到XLink!","top");
    $("#submit").click(function(){
        $("#registerForm").validate("validate").done(function(result){
            if(result){
                var params = {
                    userName: $("#userName").val(),
                    password: $("#password").val(),
                    email: $("#email").val(),
                    captcha: $("#index_code").val(),
                    index_code:$("#index_code").val()
                };
                $.getJsonData(contextPath+"/users/register/validate",params,{type:"Post"}).done(function(data){
                    console.log(data);
                    if(data.success){
                        moon.info("注册成功","top");
                        console.log("-----");
                        window.location.href=contextPath+"/index.html";
                    }else{
                        moon.error("注册失败，请稍后重试","top");
                        console.log(data);
                    }
                }).fail(function(e){
                    console.log(e);
                    moon.error("服务出错，请稍后再试","top");
                });
            }
        });
    });
    $("#loginForm:input").on("keyup",function(e){
        if(e.keyCode == 13){
            $("#submit").trigger("click");
        }
    });
    $("#changeImg").on("click",function(e){
        console.log("-----");
        var that = $(e.currentTarget).closest(".form-group").find("img");
        var src = that.attr("src");
        console.log(src);
        //var src = this.attr("src");
        that.attr("src",function(e){
            var timestamp = (new Date()).valueOf();
            src = src.substring(0,17);
            if((src.indexOf("&") >=0)){
                src = src + "xstamp=" + timestamp;
            }else{
                src = src + "?timestamp" + timestamp;
            }
            return src;
        });
    });
    /*$("#submit").click(function(){
        var _email = $("#" + obj).val();
        var reg1 = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.(?:com|cn)$/;
        if (!reg1.test(_email)) {
            alert(_email + "不是有效的email地址，请输入有效的E_mail！" );
            $("#txtEmail" ).focus();
        }
    });*/
    $("#registerForm").validate({align:'bottom',theme:"darkblue"});
});
